package com.mingqijia.gassafety.db.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mingqijia.gassafety.db.entity.Dtu;
import com.mingqijia.gassafety.db.entity.MigrateDtu;
import com.mingqijia.gassafety.db.entity.vo.*;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * <p>
 * 控制器表 Mapper 接口
 * </p>
 *
 * @author wanghai
 * @since 2022-02-21
 */
@Mapper
@Repository
public interface DtuMapper extends BaseMapper<Dtu> {

    List<Map<String, Object>> selectListByCondition(@Param("param") EquipmentListParamVO paramVO);

    Integer selectMaxNumber(@Param("ym") int ym);

    List<Dtu> getDetectorList(@Param("iMEI") String iMEI, @Param("equipmentName") String equipmentName,
                              @Param("equipmentTypes") String[] equipmentTypes, @Param("spId") String spId,
                              @Param("imeiList") List<String> imeiList, @Param("subsCode") String subsCode,
                              @Param("custName") String custName, @Param("custAddress") String custAddress,
                              @Param("custPhone") String custPhone, @Param("industryType") String industryType,
                              @Param("equipmentModel") String equipmentModel, @Param("equipmentManufacturer")
                                      String equipmentManufacturer);

    List<Dtu> getQueryList(@Param("iMEI") String iMEI, @Param("equipmentName") String equipmentName,
                           @Param("equipmentTypes") String[] equipmentTypes, @Param("spId") String spId,
                           @Param("imeiList") List<String> imeiList, @Param("memberId") String memberId,
                           @Param("industryType") String industryType, @Param("contactName") String contactName,
                           @Param("contactPhone") String contactPhone, @Param("installationAddress") String installationAddress,
                           @Param("equipmentModel") String equipmentModel, @Param("equipmentManufacturer")
                                   String equipmentManufacturer);


    void updateByIds(@Param("ids") List<String> ids);

    Dtu selectByEquipmentId(@Param("equipmentId") String equipmentId);

    void insertBatch(@Param("dtus") List<Dtu> dtus);

    void insertMigrateBatch(@Param("dtus") List<MigrateDtu> dtus);

    List<Dtu> selectEquipment(@Param("code") String code);

    List<String> selectImei();

    List<Map<String, Object>> selectAllEquipment(@Param("ids") Set<Object> ids,@Param("imei") String imei);


    Dtu selectByImei(@Param("s") String s, @Param("type") String type);

    List<Dtu> selectLikeImei(@Param("imei") String imei, @Param("type") String type);

    Dtu selectByImeiDelete(@Param("s") String s, @Param("type") String type);

    List<Dtu> selectBatchByImeiDelete(@Param("s") String s, @Param("type") String type);

    String selectPath(@Param("spId") String spId);

    List<Dtu> selectByEquipmentIds(@Param("ids") List<String> ids, @Param("spId") String spId);

    List<Dtu> selectNetInTimes();


    void deleteByImei(@Param("imei") String imei);

    void deleteByImeis(@Param("datas") List<Dtu> datas);


    List<Map<String, Object>> selectBindListByCondition(@Param("dtu") Dtu dtu, @Param("lists") List<String> lists,
                                                        @Param("activateStatus") Integer activateStatus, @Param("openStatus") Integer openStatus
            , @Param("registerStatus") Integer registerStatus);

    List<Dtu> selectByConsumerId(@Param("consumerId") String consumerId);

    void updateByImei(@Param("imeis") List<String> imeis);

    List<Map<String, Object>> consumerBindingHistory(@Param("dtu") Dtu dtu, @Param("consumerId") Integer consumerId,
                                                     @Param("event") Integer event, @Param("spId") String spId,
                                                     @Param("outOrderCode") String outOrderCode, @Param("bindChannel") Integer bindChannel);

    Integer selectCountByConsumerId(@Param("id") Integer id);

    List<Dtu> selectBindByDeviceCode(@Param("deviceCode") String deviceCode);

    List<Dtu> selectLoop(@Param("iMEI") String iMEI);

    List<Map<String, Object>> getDeviceInfo(@Param("imeiList") List<String> imeiList);


    List<Map<String, Object>> selectDtuList(@Param("startTime") String startTime, @Param("endTime") String endTime
            , @Param("imei") String imei, @Param("spId") String spId);


    //根据imei号查询对应客户信息
    List<Map<String, Object>> selectRelation(@Param("imeis") List<String> imeis);

    List<EquipmentVo> selectEquipmentBySpIds(@Param("spIds") List<String> spIds);

    List<EquipmentVo> selectEquipments(@Param("spIds") List<String> spIds);

    List<String> selectEquipmentModel(@Param("manufacturer") String manufacturer, @Param("spId") String spId);


    List<Map<String, Object>> selectStrategyId(@Param("imeis") List<String> imeis);

    Map<String, Object> selectCallInfoByImei(@Param("IMEI") String IMEI, @Param("spId") String spId);

    List<Dtu> getDetectors(@Param("iMEI") String iMEI, @Param("equipmentName") String equipmentName,
                           @Param("equipmentTypes") String[] equipmentTypes, @Param("spId") String spId,
                           @Param("imeiList") List<String> imeiList, @Param("subsCode") String subsCode,
                           @Param("custName") String custName, @Param("custAddress") String custAddress,
                           @Param("custPhone") String custPhone, @Param("industryType") String industryType,
                           @Param("equipmentModel") String equipmentModel, @Param("equipmentManufacturer")
                                   String equipmentManufacturer, @Param("orgCode") String orgCode,@Param("customerAddress") String customerAddress);

    List<Dtu> listEquipmentWithType2(@Param("iMEI") String iMEI, @Param("equipmentName") String equipmentName,
                                @Param("equipmentTypes") String[] equipmentTypes, @Param("spId") String spId,
                                @Param("imeiList") List<String> imeiList, @Param("memberId") String memberId,
                                @Param("industryType") String industryType, @Param("contactName") String contactName,
                                @Param("contactPhone") String contactPhone, @Param("installationAddress") String installationAddress,
                                @Param("equipmentModel") String equipmentModel, @Param("equipmentManufacturer")
                                        String equipmentManufacturer, @Param("orgCode") String orgCode, @Param("customerAddress") String customerAddress);

    void updateByConsumerId(@Param("id") Integer id,@Param("positionLat")  Double positionLat,@Param("positionLon")  Double positionLon,@Param("installationAddress")  String installationAddress);

    void updatePosition(@Param("position")String position,@Param("deviceId") String deviceId,@Param("date") String date);

    int deviceSuitable(@Param("imei")String imei);

    List<Map<String,Object>> runningAllEquipment(@Param("ids") Set<Object> ids,@Param("imei")  String imei,@Param("type")  Integer type);


    List<Map<String,Object>> consumerRunningStrategy(@Param("spId") String spId,
                                                     @Param("consumerId") Integer consumerId,
                                                     @Param("type")  Integer type);

    List<Map<String,Object>> runningStrategyDeviceList(@Param("spId") String spId,
                                                       @Param("imeis") Set<String> imeis);


    List<Map<String,Object>> reportAllConsumer(@Param("strategyType")  Integer strategyType,@Param("reportDate")  String reportDate);

    List<Map<String,Object>> equipmentAndConsumer(@Param("imeiType")String imeiType,@Param("imei")  String imei, @Param("strategyType")  Integer strategyType);

    List<String> queryEquipmentTypeByConsumerId(@Param("consumerId")Integer consumerId);

    String queryAddressByImei(@Param("imei")String imei);

    List<DeviceStatByDateVo> selectDeviceStatByDate(@Param("beginDate") String beginDate,@Param("endDate") String endDate);

    List<DeviceStatByDateVo> selectDeviceStatByUpdatedAt(@Param("beginDate") String beginDate,@Param("endDate") String endDate);

    List<DeviceAlarmStatVo> selectDeviceAlarmStatListByDate(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    List<DeviceAlarmStatTotalVo> selectDeviceAlarmStatTotalByDate(@Param("endDate") String endDate,
                                                                  @Param("spId") String spId,
                                                                  @Param("esCode") String esCode,
                                                                  @Param("deviceType") String deviceType);

    List<DeviceStatByDateVo> selectDeviceStat(@Param("endDate") String endDate);

    Integer selectTotalDeviceNumByParam(@Param("endDate") String endDate,
                                        @Param("spId") String spId,
                                        @Param("esCode") String esCode,
                                        @Param("deviceType") String deviceType);
    
    Integer selectTotalDeviceNumByUpdatedAt(@Param("endDate") String endDate,
                                            @Param("spId") String spId,
                                            @Param("esCode") String esCode,
                                            @Param("deviceType") String deviceType);


    List<Map<String, Object>> selectListByImeiList(@Param("imeiList") List<String> imeiList, @Param("spId") String spId);

    //根据设备号批量查询
    List<Dtu> queryByimeis(@Param("imeis") List<String> imeis);
    
    //获取更新变更的数据
    List<DeviceAlarmStatVo> selectDeviceAlarmStatListByUpdatedAt(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
    
    //获取更新变更的数据
    List<DeviceAlarmStatTotalVo> selectDeviceAlarmStatTotalByUpdatedAt(@Param("endDate") String endDate,
                                                                  @Param("spId") String spId,
                                                                  @Param("esCode") String esCode,
                                                                  @Param("deviceType") String deviceType);
    
    //查询韶关的企业映射
    List<SpMapVo> querySGSpIdMap(@Param("orgCode") String orgCode);


    //查询韶关的企业映射
    List<SpMapVo> querySGSpIdOrgCode(@Param("orgCodes") List<String> orgCodes);

    //设备运行情况
    DeviceRunningCaseVo deviceRunningCase(@Param("spId") String spId, @Param("industryType") String industryType, @Param("adCode") String adCode,
                                          @Param("townCode") String townCode, @Param("businessAreaCode") String businessAreaCode,
                                          @Param("funcCodes") List<String> funcCodes);

    //设备运行情况
    List<String> orderCondition(@Param("spId") String spId, @Param("industryType") String industryType, @Param("adCode") String adCode,
                                          @Param("townCode") String townCode, @Param("businessAreaCode") String businessAreaCode,
                                @Param("funcCodes") List<String> funcCodes);

    /**
     * 大屏客户数据按层级统计
     * @param spIds
     * @param level
     * @return
     */
    List<ConsumerLocationGroupItemVO> selectConsumerGroupsList(@Param("spIds") List<String> spIds,
                                                              @Param("level") String level,
                                                               @Param("funcCodes") List<String> funcCodes);

    /**
     * 获取boundary里面客户数据
     * @param spIds
     * @param polygon
     * @return
     */
    List<ConsumerLocationItemVO> selectConsumerLocationList(@Param("spIds") List<String> spIds,
                                                            @Param("polygon") String polygon,
                                                            @Param("funcCodes") List<String> funcCodes);

    /**
     * 大屏客户数据按层级统计
     * @param spId
     * @param industryType
     * @param adCode
     * @param townCode
     * @param businessAreaCode
     * @return
     */
    List<ConsumerLocationGroupItemVO> queryConsumerGroupList(@Param("spIds") List<String> spIds, @Param("industryType") String industryType, @Param("adCode") String adCode,
                                @Param("townCode") String townCode, @Param("businessAreaCode") String businessAreaCode,
                                                             @Param("funcCodes") List<String> funcCodes);

    /**
     * 大屏客户数据按层级统计
     * @param spId
     * @param industryType
     * @param adCode
     * @param townCode
     * @param businessAreaCode
     * @return
     */
    List<ConsumerLocationItemVO> queryConsumerLocationList(@Param("spIds") List<String> spIds, @Param("industryType") String industryType, @Param("adCode") String adCode,
                                                             @Param("townCode") String townCode, @Param("businessAreaCode") String businessAreaCode,
                                                           @Param("funcCodes") List<String> funcCodes, @Param("polygon") String polygon);


    GetCondtionListVo getAlarmConditionList(@Param("spIds") List<String> spIds, @Param("industryType") String industryType, @Param("adCode") String adCode,
                             @Param("townCode") String townCode, @Param("businessAreaCode") String businessAreaCode,@Param("deviceType") Integer deviceType,
                                  @Param("funcCodes") List<String> funcCodes);

    GetCondtionListVo getBrokenConditionList(@Param("spIds") List<String> spIds, @Param("industryType") String industryType, @Param("adCode") String adCode,
                                  @Param("townCode") String townCode, @Param("businessAreaCode") String businessAreaCode,@Param("deviceType") Integer deviceType,
                                   @Param("funcCodes") List<String> funcCodes);


    //查询当日新增设备数
    Integer selectOnDayDeviceNum(@Param("spIds") List<String> spIds);

    //获取报警设备数据
    List<ReportDeviceDataVo> getReportDeviceData(@Param("spId") String spId,
                                                 @Param("deviceId") String deviceId,
                                                 @Param("dataType") Integer dataType);

    //获取报警数据
    List<ReportAlarmDataVo> getReportAlarmData(@Param("spId") String spId,
                                               @Param("deviceId") String deviceId,
                                               @Param("historyAlarmId") Integer historyAlarmId);

    /**
     * 获取用户的数设备数据权限
     * @param consumerIds
     * @return
     */
    List<String> getDepartConsumerDeviceIds(@Param("spId") String spId,
                                            @Param("consumerIds") List<Integer> consumerIds);
}
